define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/index',
                    add_url: 'distribute_task/add',
                    edit_url: 'distribute_task/edit',
                    del_url: 'distribute_task/del',
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var columns = [
                {checkbox: true},
                {field: 'id', title: __('Id'), sortable: true},
                {field: 'title', title: __('标题'), operate: 'LIKE'},
                //{field: 'topic', title: __('话题')},
                // {field: 'user_id', title: __('用户ID'),formatter:Table.api.formatter.search},

                {field: 'user_id', title: __('用户信息'),events:{
                    'click .clickOpen':function (e,value,row,index) {
                        //todo一些点击事件后要做的操作
                        //打印dom对象
                        layer.open({
                            type: 2,
                            title: '用户信息',
                            maxmin: true,
                            shadeClose: false, // 点击遮罩关闭层
                            area: ['800px', '620px'], //子页面大小
                            btn: ['确定'],
                            btnAlign: 'c',
                            content: 'index?zi=1&user_id='+row.user_id, // iframe的url
                            yes: function (index, layero) { //按钮【按钮一】的回调
                                layer.close(index);
                            }
                        })
                    }
                    },formatter:function (value, row, index) {
                        // value 当前这个表格格子的值，row 当前行数据，index当前行索引值
                        if(row.user_id){
                            return "<a href='javascript:;' class='clickOpen' data-id='"+row.user_id+"'>"+'【'+row.user_id+'】<br>'+row.nickname+'<br>'+row.mobile+"</a>";
                        }
                    }
                },
                // {field: 'user_id', title: __('用户信息'),formatter:function (value, row, index) {
                //         if(row.user_id){
                //             return "<div  class='clickOpen' data-id='"+row.user_id+"'>"+'【'+row.user_id+'】'+row.nickname+'<br>'+row.mobile+"</div>";
                //         }else{
                //             return '';
                //         }
                // }, operate: false},
                {field: 'imgs', title: __('任务图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                {field: 'user_imgs', title: __('审核图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                {field: 'illegal_img', title: __('违规截图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                
                {
                    //单元格点击弹出
                    field: 'user_content',
                    title: __('审核内容'),
                    operate: false,
                    // events:{
                    //     "click .show_mark":function(e, value, row, index){
                    //        layer.open({
                    //             type: 1,
                    //             area: ['650px', '260px'],
                    //             title: "备注信息",
                    //             shade: 0.8,
                    //             closeBtn: 1,
                    //             shadeClose: true,
                    //             scrollbar: false ,//屏蔽浏览器滚动条
                    //             // skin: 'layui-layer-rim', //加上边框
                    //             content: '<div style="text-align: center;line-height: 25px; ">' + row.user_content_1 + ' </div> ',
                    //             btn: ['确定'],
                    //         });
                    //     }
                    // },
                    formatter:function(index,row){
                        if(row.user_content_status == 1){
                            return "<a href='"+row.user_content_1+"' class='show_mark'  target='_blank'>"+row.user_content+"</a>";
                        }else if(row.user_content_status == 2){
                            return "<a href='"+row.user_content+"' class='show_mark'  target='_blank'>"+row.user_content+"</a>";
                        }else{
                            return row.user_content;
                        }
                            
                    }
                },
                {field: 'statistics_num', title: __('浏览数量'), operate: false,sortable: true},
                {field: 'product_id', title: __('产品ID'), operate: false,sortable: true},
                {field: 'price', title: __('任务金额'), operate: false},
                //{field: 'price_status', title: __('资金到账状态'), formatter: Table.api.formatter.status, searchList: {'0': '未到账', '1': '已到账'}},
                {field: 'type', title: __('任务所属'), operate:'LIKE'},
                //{field: 'task_type', title: __('任务类型'), formatter: Table.api.formatter.status, searchList: {'1': '小红书', '2': '抖音','3':'快手'},width: 120, sortable: true},
                {field: 'status', title: __('任务状态'), formatter: Table.api.formatter.status, searchList: {'0': '待接单', '1': '已接单','2':'已提交待审核','3':'已完成','-1':'已拒绝','-2':'已退回','-3':'待上架','-4':'已删除'},width: 120, sortable: true},
                {field: 'is_del', title: __('帖子状态'), formatter: Table.api.formatter.status, searchList: {'0': '正常', '1': '已删除'},width: 120, sortable: true},
                {field: 'is_repetition', title: __('重复提交'), formatter: Table.api.formatter.status, searchList: {'0': '否', '1': '是'},width: 120, sortable: true},
                {field: 'character_type', title: __('账号人设'), formatter: Table.api.formatter.status, searchList: { '1':'素人','2': '官方合作'},width: 140, sortable: true},
                {field: 'receive_time', title: __('接单时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                {field: 'complete_time', title: __('完成时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                //{field: 'add_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                {
                    field: 'operate',
                    title: __('Operate'),
                    table: table,
                    events: Table.api.events.operate,
                    formatter: Table.api.formatter.operate,
                    buttons: [
                        {
                            name: 'status',
                            title: '违规已处理',
                            text: '违规已处理',
                            confirm: '是违规已处理？',
                            classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                            url: function (row) {
                                return 'distribute_task/update_status?is_illegal=2&id='+row.id;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.is_illegal==1){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            success: function (res){
                                table.bootstrapTable('refresh');
                            }
                        },
                        {
                            name: 'status',
                            title: '上架任务',
                            text: '上架任务',
                            confirm: '是否上架任务？',
                            classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                            url: function (row) {
                                return 'distribute_task/update_status?status=0&id='+row.id;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.status==-3){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            success: function (res){
                                table.bootstrapTable('refresh');
                            }
                        },
                        {
                            name: 'status',
                            title: '下架任务',
                            text: '下架任务',
                            confirm: '是否下架任务？',
                            classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                            url: function (row) {
                                return 'distribute_task/update_status?status=-3&id='+row.id;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.status==0){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            success: function (res){
                                table.bootstrapTable('refresh');
                            }
                        },
                        {
                            name: 'status',
                            title: '通过审核',
                            text: '通过审核',
                            confirm: '是否通过审核？通过后该用户即可获取相对应佣金',
                            classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                            url: function (row) {
                                return 'distribute_task/update_status?status=1&id='+row.id;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.status==2){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            success: function (res){
                                table.bootstrapTable('refresh');
                            }
                        },
                        {
                            name: 'click',
                            title: __('拒绝审核'),
                            text: '拒绝审核',
                            classname: 'btn btn-xs btn-info btn-click',
                            click: function (e, row) {
                                Layer.prompt({
                                    title: "拒绝原因",
                                    success: function (layero) {
                                        $("input", layero).prop("placeholder", "请输入拒绝审核原因");
                                    }
                                }, function (value) {
                                    Fast.api.ajax({
                                        url: 'distribute_task/update_status',
                                        data: {remark: value,status:-1,id:row.id},
                                    }, function (data, ret) {
                                        table.bootstrapTable('refresh');
                                        Layer.closeAll();
                                        //$(".btn-refresh").trigger("click");
                                        //return false;
                                    });
                                });
                                return false;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.status==2){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            
                        },
                        {
                            name: 'click',
                            title: __('统计浏览'),
                            text: '统计浏览',
                            classname: 'btn btn-xs btn-info btn-click',
                            click: function (e, row) {
                                Layer.prompt({
                                    title: "统计浏览",
                                    success: function (layero) {
                                        $("input", layero).prop("placeholder", "请输入浏览数量");
                                    }
                                }, function (value) {
                                    Fast.api.ajax({
                                        url: 'distribute_task/statistics_update_status',
                                        data: {statistics_num: value,id:row.id},
                                    }, function (data, ret) {
                                        table.bootstrapTable('refresh');
                                        Layer.closeAll();
                                    });
                                });
                                return false;
                            },
                            visible: function (row) {
                                //返回true时按钮显示,返回false隐藏
                                if(row.status==3 && row.statistics_num == 0){
                                    return true;
                                }else {
                                    return false;
                                }
                            },
                            
                        },
                        // {
                        //     name: 'status',
                        //     title: '拒绝审核',
                        //     text: '拒绝审核',
                        //     confirm: '是否拒绝审核？通过后该用户即可获取相对应佣金',
                        //     classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                        //     url: function (row) {
                        //         return 'distribute_task/update_status?id='+row.id;
                        //     },
                        //     visible: function (row) {
                        //         //返回true时按钮显示,返回false隐藏
                        //         if(row.is_contact==2){
                        //             return true;
                        //         }else {
                        //             return false;
                        //         }
                        //     },
                        //     success: function (res){
                        //         table.bootstrapTable('refresh');
                        //     }
                        // },
                    ],
                }
            ];
            if(Config.group_id == 6){
                columns = [
                    {field: 'id', title: __('Id'), sortable: true},
                    {field: 'title', title: __('标题'), operate: 'LIKE'},
                    {field: 'imgs', title: __('任务图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                    {
                        //单元格点击弹出
                        field: 'user_content',
                        title: __('审核内容'),
                        operate: false,
                        formatter:function(index,row){
                            if(row.user_content_status == 1){
                                return "<a href='"+row.user_content_1+"' class='show_mark'  target='_blank'>"+row.user_content+"</a>";
                            }else if(row.user_content_status == 2){
                                return "<a href='"+row.user_content+"' class='show_mark'  target='_blank'>"+row.user_content+"</a>";
                            }else{
                                return row.user_content;
                            }
                                
                        }
                    },
                    {field: 'user_imgs', title: __('审核图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                    {field: 'statistics_num', title: __('浏览数量'), operate: false,sortable: true},
                    {field: 'status', title: __('任务状态'), formatter: Table.api.formatter.status, searchList: {'0': '待接单', '1': '已接单','2':'已提交待审核','3':'已完成','-1':'已拒绝','-2':'已退回','-3':'待上架','-4':'已删除'},width: 120, sortable: true},
                    {field: 'receive_time', title: __('接单时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    {field: 'complete_time', title: __('完成时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    // {
                    //     field: 'operate',
                    //     title: __('Operate'),
                    //     table: table,
                    //     events: Table.api.events.operate,
                    //     formatter: Table.api.formatter.operate,
                    // }
                ];
            }
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'receive_time',
                search: false,
                pageSize: 10,
                searchFormVisible: Config.zi ? false : true  ,
                columns: [
                    columns
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
            if(Config.zi != 1){
                $('.commonsearch-table').removeClass('hidden');
            }
            

            $(".btn-add").data("area",["70%","90%"]);
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["70%","90%"]);
            })

            
            


        },
        user_index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/user_index?ids='+ Config.ids,
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('标题')},
                        {field: 'topic', title: __('话题')},
                        {field: 'nickname', title: __('指定用户'),formatter:function (value, row, index) {
                                return '【'+row.user_id+'】'+value;
                        }},
                        {field: 'imgs', title: __('任务图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'user_imgs', title: __('审核图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'user_content', title: __('审核内容'), operate: false},
                        {field: 'price', title: __('任务金额'), operate: false},
                        {field: 'price_status', title: __('资金到账状态'), formatter: Table.api.formatter.status, searchList: {'0': '未到账', '1': '已到账'}},
                        {field: 'type', title: __('任务类型'), formatter: Table.api.formatter.status, searchList: {'1': '自动分发', '2': '自行领取'}},
                        {field: 'status', title: __('任务状态'), formatter: Table.api.formatter.status, searchList: {'0': '待接单', '1': '已接单','2':'已提交待审核','3':'已完成','-1':'已拒绝'},width: 120},
                        {field: 'end_time', title: __('要求完成时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, operate: false},
                        {field: 'add_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        statistics_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/statistics_list?ids='+ Config.ids,
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                    del_url: 'distribute_task/statistics_del',
                    add_url: 'distribute_task/statistics_add',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'name', title: __('浏览用户名')},
                        {field: 'num', title: __('浏览数量'), sortable: true},
                        {field: 'url', title: __('浏览链接')},
                        {field: 'add_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        statistics_add: function () {
            Controller.api.bindevent();
        },
        user_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/user_list',
                    add_url: 'distribute_task/user_list_add',
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'nickname', title: __('用户名')},
                        {field: 'task_sum', title: __('接单数量'), operate: false},
                        {field: 'wc_task_sum', title: __('完成任务数量'), operate: false},
                        {field: 'task_price', title: __('待提现佣金'), operate: false, sortable: true},
                        {field: 'withdraw_sum', title: __('已提现佣金'), operate: false},
                        {field: 'handingfee_sum', title: __('提现总手续费'), operate: false},
                        {field: 'character_type', title: __('账号人设'), formatter: Table.api.formatter.status, searchList: { '1':'素人','2': '官方合作'},width: 140, sortable: true},
                        {field: 'is_supervise', title: __('是否监管'), formatter: Table.api.formatter.status, searchList: {'1': '是', '0': '否'}},
                        {field: 'task_status', title: __('状态'), formatter: Table.api.formatter.status, searchList: { '-1':'已冻结','1': '正常'},width: 100, sortable: true},
                        {field: 'task_time', title: __('成为团长时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            width: 400,
                            buttons: [
                                {
                                    name: 'status',
                                    title: '冻结团长资格',
                                    text: '冻结团长资格',
                                    confirm: '是否冻结该用户的团长资格？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'distribute_task/detele_user_tz?status=-1&id='+row.id;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.task_status==1){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'status',
                                    title: '解除冻结团长资格',
                                    text: '解除冻结团长资格',
                                    confirm: '是否解除冻结团长资格？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'distribute_task/detele_user_tz?status=1&id='+row.id;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.task_status==-1){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'status',
                                    title: '设为素人',
                                    text: '设为素人',
                                    confirm: '是否将该用户设置为素人？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'distribute_task/set_character_type?status=1&id='+row.id;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.character_type==2){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'status',
                                    title: '设为官方合作',
                                    text: '设为官方合作',
                                    confirm: '是否将该用户设置为官方合作？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'distribute_task/set_character_type?status=2&id='+row.id;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.character_type==1){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: '财务记录',
                                    text: __('财务记录'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'distribute_task/withdraw_list'
                                },
                                {
                                    name: '任务管理',
                                    text: __('任务管理'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'distribute_task/user_index'
                                },
                                {
                                    name: 'status',
                                    title: '开始监管',
                                    text: '开始监管',
                                    confirm: '是否确定开始监管该用户？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'user/user/setSupervise?is_supervise=1&id='+row.user_id;
                                    },
                                    visible: function (row) {
                                        if(row.is_supervise==1){
                                            return false;
                                        }else {
                                            return true;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },{
                                    name: 'status',
                                    title: '取消监管',
                                    text: '取消监管',
                                    confirm: '是否确定取消监管该用户？',
                                    classname: 'btn btn-success btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'user/user/setSupervise?is_supervise=0&id='+row.user_id;
                                    },
                                    visible: function (row) {
                                        if(row.is_supervise==1){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                }
                                
                            ],
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });

            $('.commonsearch-table').removeClass('hidden');

        },
        withdraw_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/withdraw_list?ids='+ Config.ids,
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'price', title: __('金额')},
                        {field: 'type', title: __('类型'), formatter: Table.api.formatter.status, searchList: {'1': '任务佣金', '2': '提现申请','3':'被拒绝提现'}},
                        {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {'1': '已完成', '2': '申请中','-1':'已拒绝'}},
                        {field: 'add_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        withdraw: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/withdraw',
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('提现用户'),formatter:function (value, row, index) {
                                if(row.user_id){
                                    return '【'+row.user_id+'】'+value;
                                }else{
                                    return '';
                                }
                        }},
                        {field: 'orderid', title: __('订单号'), operate: false},
                        {
                            //单元格点击弹出
                            field: 'imgs',
                            title: __('视频URL'),
                            operate: false,
                            formatter:function(index,row){
                                if(row.imgs == ''){
                                    return "";
                                }else{
                                    return "<a href='"+row.imgs+"' class='show_mark'  target='_blank'>"+row.imgs+"</a>";
                                }
                                    
                            }
                        },
                        {field: 'money', title: __('提现金额')},
                        {field: 'handingfee', title: __('手续费'), operate: false},
                        {field: 'remark', title: __('拒绝理由'), operate: false},
                        {field: 'is_supervise', title: __('是否监管'), formatter: Table.api.formatter.status, searchList: {'1': '是', '0': '否'}},
                        {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {'created': '申请中', 'successed': '提现成功','rejected':'已拒绝'}},
                        {field: 'add_time', title: __('提现时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            width: 200,
                            buttons: [
                                {
                                    name: 'status',
                                    title: '通过审核',
                                    text: '通过审核',
                                    confirm: '是否通过审核？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'distribute_task/withdraw_update_status?status=1&id='+row.id;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status=='created'){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'click',
                                    title: __('拒绝审核'),
                                    text: '拒绝审核',
                                    classname: 'btn btn-xs btn-info btn-click',
                                    click: function (e, row) {
                                        Layer.prompt({
                                            title: "拒绝理由",
                                            success: function (layero) {
                                                $("input", layero).prop("placeholder", "请输入拒绝审核理由");
                                            }
                                        }, function (value) {
                                            Fast.api.ajax({
                                                url: 'distribute_task/withdraw_update_status',
                                                data: {remark: value,status:-1,id:row.id},
                                            }, function (data, ret) {
                                                table.bootstrapTable('refresh');
                                                Layer.closeAll();
                                            });
                                        });
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status=='created'){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    
                                },
                                {
                                    name: 'status',
                                    title: '开始监管',
                                    text: '开始监管',
                                    confirm: '是否确定开始监管该用户？',
                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'user/user/setSupervise?is_supervise=1&id='+row.user_id;
                                    },
                                    visible: function (row) {
                                        if(row.is_supervise==1){
                                            return false;
                                        }else {
                                            return true;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                },{
                                    name: 'status',
                                    title: '取消监管',
                                    text: '取消监管',
                                    confirm: '是否确定取消监管该用户？',
                                    classname: 'btn btn-success btn-xs btn-magic btn-ajax',
                                    url: function (row) {
                                        return 'user/user/setSupervise?is_supervise=0&id='+row.user_id;
                                    },
                                    visible: function (row) {
                                        if(row.is_supervise==1){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },
                                    success: function (res){
                                        table.bootstrapTable('refresh');
                                    }
                                }
                            ],
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        shop_fund: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distribute_task/shop_fund',
                    multi_url: 'distribute_task/multi',
                    dragsort_url: 'ajax/weigh',
                    table: 'distribute_task',
                }
            });
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize: 10,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'task_id', title: __('任务ID')},
                        {field: 'price', title: __('本次变更余额'), operate: false},
                        {field: 'is_freeze', title: __('是否为冻结金额'), formatter: Table.api.formatter.status, searchList: {'1': '是', '0': '否'}},
                        {field: 'freeze_type', title: __('是否已经解冻'), formatter: Table.api.formatter.status, searchList: {'1': '是', '0': '否'}},
                        {field: 'type', title: __('类型'), formatter: Table.api.formatter.status, searchList: {'1': '支出', '2': '充值','3':'解冻'}},
                        {field: 'add_time', title: __('新增时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        add: function () {
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
            $(".product").on("click", function() {
                var that = this;
                layer.open({
                    type: 2,
                    title: '标题',
                    maxmin: true,
                    shadeClose: false, // 点击遮罩关闭层
                    area: ['800px', '620px'], //子页面大小
                    btn: ['确定上传'],
                    btnAlign: 'c',
                    content: 'product_add', // iframe的url
                    yes: function (index, layero) { //按钮【按钮一】的回调
                        
                        var body = layer.getChildFrame('body', index);
                        // 根据formId获取form表单数据
                        var formdata = body.find("#fromId").serializeArray();
                        Fast.api.ajax({
                            url: 'distribute_task/product_add',
                            data: formdata,
                        }, function (data, res) {
                            if(res.code == 1){
                                $('.product_id').val(res.data);
                                $('.title').html(formdata[1].value);
                                layer.close(index);
                            }
                        });

                    }
                })
            });

            $('#task_type').change(function() {
                var selectedValue = $('#task_type option:selected').val();
                if(selectedValue == 1){
                    $('.titel').css('display','block')
                }else  if(selectedValue == 2){
                    $('.titel').css('display','none')
                }
            })

            $('#type').change(function() {
                if($(this).val() == '电事聚小红书'){
                    $('.add_product').css('display','none');
                    $('.imgs1').css('display','block');
                }else{
                    $('.add_product').css('display','block');
                    $('.imgs1').css('display','none');
                }
            })

        },
        edit: function () {
            Controller.api.bindevent();
            $(".product").on("click", function() {
                var that = this;
                layer.open({
                    type: 2,
                    title: '标题',
                    maxmin: true,
                    shadeClose: false, // 点击遮罩关闭层
                    area: ['800px', '620px'], //子页面大小
                    btn: ['确定上传'],
                    btnAlign: 'c',
                    content: 'product_add', // iframe的url
                    yes: function (index, layero) { //按钮【按钮一】的回调
                        
                        var body = layer.getChildFrame('body', index);
                        // 根据formId获取form表单数据
                        var formdata = body.find("#fromId").serializeArray();
                        Fast.api.ajax({
                            url: 'distribute_task/product_add',
                            data: formdata,
                        }, function (data, res) {
                            if(res.code == 1){
                                $('.product_id').val(res.data);
                                $('.title').html(formdata[1].value);
                                $('.status').html('已上架');
                                layer.close(index);
                            }
                        });

                    }
                })
            });
        },
        product_add: function () {
            Controller.api.bindevent();
        },
        config: function () {
            Controller.api.bindevent();
        },
        user_list_add: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $(document).on("change", "#c-type", function () {
                    $("#c-pid option[data-type='all']").prop("selected", true);
                    $("#c-pid option").removeClass("hide");
                    $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
                    $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
